<%@ page import="java.sql.*" %><%--
  Created by IntelliJ IDEA.
  User: hongz
  Date: 2023/10/14
  Time: 10:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>购物商城</title>
</head>
<body>
<a href="history_book.jsp">历史图书</a>
<a href="computer_book.jsp">计算机图书</a>

<table>
    <tr>
        <td>用户名</td>
        <td>密码</td>
    </tr>


    <% 
    
    String driver = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://127.0.0.1:3306/demo?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai";

        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

        try {
            Connection conn = DriverManager.getConnection(url, "root", "1234");
            Statement statement = conn.createStatement();
            String sql = "select * from user";
            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {

    %>
    <tr>
        <td><%=resultSet.getString("username")%></td>
        <td><%=resultSet.getString("password")%></td>
    </tr>
    <%
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    %>

</table>
</body>
</html>
